function Food(el){
    // 保存地图对象
    this.el = el
    // 保存食物属性
    this.len = 20
    this.foodX = 0
    this.foodY = 0
    this.foodObj=null
}

Food.prototype.create = function(){
    // 页面创建div标签对象
    let divObj = document.createElement('div')
    // 设置样式
    divObj.style.width=this.len+'px'
    divObj.style.height=this.len+'px'
    divObj.style.background='green'
    divObj.style.position='absolute'
    // 单独保证食物对象
    this.foodObj=divObj
    // 追加页面显示
    this.el.appendChild(divObj)
    // 随机出现食物
    this.move()
}
Food.prototype.move = function(){
    
    // 计算宽高最多可出现的食物个数
    let maxfoodX = this.el.clientWidth/this.len-1
    let maxfoodY = this.el.clientHeight/this.len-1
    // 确定食物的坐标然后计算宽高
    this.foodX = Math.floor(Math.random()*(maxfoodX-0+1)+0)*this.len
    this.foodY = Math.floor(Math.random()*(maxfoodY-0+1)+0)*this.len
    // 食物左右坐标
    
    this.foodObj.style.top=this.foodY+'px'
    this.foodObj.style.left=this.foodX+'px'
    // console.log( this.foodY, this.foodX);
    
}